﻿using System;
using System.Threading;
using Mono.Collections.Generic;

namespace Mono.Cecil
{
	// Token: 0x02000063 RID: 99
	public sealed class EventDefinition : EventReference, IMemberDefinition, ICustomAttributeProvider, IMetadataTokenProvider
	{
		// Token: 0x17000065 RID: 101
		// (get) Token: 0x060003A8 RID: 936 RVA: 0x0001B070 File Offset: 0x00019270
		// (set) Token: 0x060003A9 RID: 937 RVA: 0x00003515 File Offset: 0x00001715
		public EventAttributes Attributes
		{
			get
			{
				return (EventAttributes)this.attributes;
			}
			set
			{
				this.attributes = (ushort)value;
			}
		}

		// Token: 0x17000066 RID: 102
		// (get) Token: 0x060003AA RID: 938 RVA: 0x0001B088 File Offset: 0x00019288
		// (set) Token: 0x060003AB RID: 939 RVA: 0x0000351F File Offset: 0x0000171F
		public MethodDefinition AddMethod
		{
			get
			{
				bool flag = this.add_method != null;
				MethodDefinition result;
				if (flag)
				{
					result = this.add_method;
				}
				else
				{
					this.InitializeMethods();
					result = this.add_method;
				}
				return result;
			}
			set
			{
				this.add_method = value;
			}
		}

		// Token: 0x17000067 RID: 103
		// (get) Token: 0x060003AC RID: 940 RVA: 0x0001B0C0 File Offset: 0x000192C0
		// (set) Token: 0x060003AD RID: 941 RVA: 0x00003529 File Offset: 0x00001729
		public MethodDefinition InvokeMethod
		{
			get
			{
				bool flag = this.invoke_method != null;
				MethodDefinition result;
				if (flag)
				{
					result = this.invoke_method;
				}
				else
				{
					this.InitializeMethods();
					result = this.invoke_method;
				}
				return result;
			}
			set
			{
				this.invoke_method = value;
			}
		}

		// Token: 0x17000068 RID: 104
		// (get) Token: 0x060003AE RID: 942 RVA: 0x0001B0F8 File Offset: 0x000192F8
		// (set) Token: 0x060003AF RID: 943 RVA: 0x00003533 File Offset: 0x00001733
		public MethodDefinition RemoveMethod
		{
			get
			{
				bool flag = this.remove_method != null;
				MethodDefinition result;
				if (flag)
				{
					result = this.remove_method;
				}
				else
				{
					this.InitializeMethods();
					result = this.remove_method;
				}
				return result;
			}
			set
			{
				this.remove_method = value;
			}
		}

		// Token: 0x17000069 RID: 105
		// (get) Token: 0x060003B0 RID: 944 RVA: 0x0001B130 File Offset: 0x00019330
		public bool HasOtherMethods
		{
			get
			{
				bool flag = this.other_methods != null;
				bool result;
				if (flag)
				{
					result = (this.other_methods.Count > 0);
				}
				else
				{
					this.InitializeMethods();
					result = !this.other_methods.IsNullOrEmpty<MethodDefinition>();
				}
				return result;
			}
		}

		// Token: 0x1700006A RID: 106
		// (get) Token: 0x060003B1 RID: 945 RVA: 0x0001B178 File Offset: 0x00019378
		public Collection<MethodDefinition> OtherMethods
		{
			get
			{
				bool flag = this.other_methods != null;
				Collection<MethodDefinition> result;
				if (flag)
				{
					result = this.other_methods;
				}
				else
				{
					this.InitializeMethods();
					bool flag2 = this.other_methods == null;
					if (flag2)
					{
						Interlocked.CompareExchange<Collection<MethodDefinition>>(ref this.other_methods, new Collection<MethodDefinition>(), null);
					}
					result = this.other_methods;
				}
				return result;
			}
		}

		// Token: 0x1700006B RID: 107
		// (get) Token: 0x060003B2 RID: 946 RVA: 0x0001B1CC File Offset: 0x000193CC
		public bool HasCustomAttributes
		{
			get
			{
				bool flag = this.custom_attributes != null;
				bool result;
				if (flag)
				{
					result = (this.custom_attributes.Count > 0);
				}
				else
				{
					result = this.GetHasCustomAttributes(this.Module);
				}
				return result;
			}
		}

		// Token: 0x1700006C RID: 108
		// (get) Token: 0x060003B3 RID: 947 RVA: 0x0001B208 File Offset: 0x00019408
		public Collection<CustomAttribute> CustomAttributes
		{
			get
			{
				return this.custom_attributes ?? this.GetCustomAttributes(ref this.custom_attributes, this.Module);
			}
		}

		// Token: 0x1700006D RID: 109
		// (get) Token: 0x060003B4 RID: 948 RVA: 0x0001B238 File Offset: 0x00019438
		// (set) Token: 0x060003B5 RID: 949 RVA: 0x0000353D File Offset: 0x0000173D
		public bool IsSpecialName
		{
			get
			{
				return this.attributes.GetAttributes(512);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(512, value);
			}
		}

		// Token: 0x1700006E RID: 110
		// (get) Token: 0x060003B6 RID: 950 RVA: 0x0001B25C File Offset: 0x0001945C
		// (set) Token: 0x060003B7 RID: 951 RVA: 0x00003557 File Offset: 0x00001757
		public bool IsRuntimeSpecialName
		{
			get
			{
				return this.attributes.GetAttributes(1024);
			}
			set
			{
				this.attributes = this.attributes.SetAttributes(1024, value);
			}
		}

		// Token: 0x1700006F RID: 111
		// (get) Token: 0x060003B8 RID: 952 RVA: 0x0001B280 File Offset: 0x00019480
		// (set) Token: 0x060003B9 RID: 953 RVA: 0x00003571 File Offset: 0x00001771
		public new TypeDefinition DeclaringType
		{
			get
			{
				return (TypeDefinition)base.DeclaringType;
			}
			set
			{
				base.DeclaringType = value;
			}
		}

		// Token: 0x17000070 RID: 112
		// (get) Token: 0x060003BA RID: 954 RVA: 0x0000A3A0 File Offset: 0x000085A0
		public override bool IsDefinition
		{
			get
			{
				return true;
			}
		}

		// Token: 0x060003BB RID: 955 RVA: 0x0000357C File Offset: 0x0000177C
		public EventDefinition(string name, EventAttributes attributes, TypeReference eventType) : base(name, eventType)
		{
			this.attributes = (ushort)attributes;
			this.token = new MetadataToken(TokenType.Event);
		}

		// Token: 0x060003BC RID: 956 RVA: 0x0001B2A0 File Offset: 0x000194A0
		private void InitializeMethods()
		{
			ModuleDefinition module = this.Module;
			bool flag = module == null;
			if (!flag)
			{
				object syncRoot = module.SyncRoot;
				lock (syncRoot)
				{
					bool flag3 = this.add_method != null || this.invoke_method != null || this.remove_method != null;
					if (!flag3)
					{
						bool flag4 = !module.HasImage();
						if (!flag4)
						{
							module.Read<EventDefinition>(this, delegate(EventDefinition @event, MetadataReader reader)
							{
								reader.ReadMethods(@event);
							});
						}
					}
				}
			}
		}

		// Token: 0x060003BD RID: 957 RVA: 0x0001B34C File Offset: 0x0001954C
		public override EventDefinition Resolve()
		{
			return this;
		}

		// Token: 0x040000EE RID: 238
		private ushort attributes;

		// Token: 0x040000EF RID: 239
		private Collection<CustomAttribute> custom_attributes;

		// Token: 0x040000F0 RID: 240
		internal MethodDefinition add_method;

		// Token: 0x040000F1 RID: 241
		internal MethodDefinition invoke_method;

		// Token: 0x040000F2 RID: 242
		internal MethodDefinition remove_method;

		// Token: 0x040000F3 RID: 243
		internal Collection<MethodDefinition> other_methods;
	}
}
